package com.leyou.item.service.impl;

import com.leyou.item.entity.SpecGroup;
import com.leyou.item.entity.SpecParam;
import com.leyou.item.mapper.LyBaseMapper;
import com.leyou.item.mapper.lymapper.SpecGroupMapper;
import com.leyou.item.service.SpecGroupService;
import com.leyou.item.service.SpecParamService;
import com.leyou.item.service.base.AbstractBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author linzx
 * @date 2020/3/25
 */
@Service
public class SpecGroupServiceImpl extends AbstractBaseService<SpecGroup> implements SpecGroupService {
    @Autowired
    private SpecGroupMapper specGroupMapper;
    @Autowired
    private SpecParamService specParamService;

    @Override
    protected LyBaseMapper<SpecGroup> getMapper() {
        return specGroupMapper;
    }


    @Override
    public List<SpecGroup> findSpecGroupWithSpecParamsByCid(Long cid) {
        SpecGroup specGroup = new SpecGroup();
        specGroup.setCid(cid);
        List<SpecGroup> specGroupList = this.select(specGroup);
        SpecParam specParam = new SpecParam();
        for (SpecGroup group : specGroupList) {
            specParam.setGroupId(group.getId());
            List<SpecParam> specParamList = specParamService.select(specParam);
            group.setParams(specParamList);
        }
        return specGroupList;
    }
}
